package org.testfire.realm.view.json.translator;

import org.json.JSONException;

import java.util.List;

/*
 * @(#)JsonTranslator.java
 *
 *
 *
 * ver 1.0 Sep 4, 2007 ggranum
 */

public interface JsonTranslator<T>
{
	String toJson(T object);

	String toJson(T object, String fields) throws JSONException;

	String toJson(List<T> object);

	/**
	 * Create a TRANSIENT VERSION of the object type from the JSON string.
	 * <p/>
	 * For instance, if <code>json</code> represents a Test object, then a new
	 * TestEntity will be created, all of the values in the JSON object will be
	 * set on the new Test, and the new test will be returned.
	 * <p/>
	 * This method should perform NO database operations.
	 *
	 * @param json A JSON representation of an object.
	 * @return A Transient entity. This object should never be persisted or updated,
	 *         as it should not have been retrieved from the database, and may have an invalid ID placed on it.
	 * @throws JSONException On a parse error.
	 */
	T toObject(String json) throws JSONException;

	String toJsonArray(List<T> objects, String fields) throws JSONException;

	T copyValues(T to, T from);
}
